package cn.edu.nju.oraldefense.action;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;

import cn.edu.nju.oraldefense.model.Teacher;
import cn.edu.nju.oraldefense.service.TeacherService;

import com.opensymphony.xwork2.ActionSupport;

public class TeacherModifyAction extends ActionSupport {

	private Teacher teacher;
	private TeacherService teacherService;
	private boolean success;

	@JSON(serialize = false)
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@JSON(serialize = false)
	public TeacherService getTeacherService() {
		return teacherService;
	}

	@Resource
	public void setTeacherService(TeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public String execute() {
		//System.out.println(teacher);
		Teacher t = teacherService.getById(teacher.getId());
		teacher.setPassword(t.getPassword());
		teacherService.modifyTeacher(teacher);
		success = true;
		return SUCCESS;
	}

}
